<?php

/**
 * This is the model class for table "res_user".
 *
 * The followings are the available columns in table 'res_user':
 * @property integer $id
 * @property string $name
 * @property boolean $active
 * @property string $login
 * @property string $password
 * @property string $create_date
 * @property string $write_date
 * @property integer $create_uid
 * @property integer $write_uid
 * @property string $timezone
 * @property integer $menu
 * @property string $email
 * @property integer $language
 * @property integer $login_try
 * @property string $signature
 * @property string $salt
 * @property integer $main_company
 * @property integer $employee
 * @property integer $company
 *
 * The followings are the available model relations:
 * @property PartyCategory[] $partyCategories
 * @property PartyCategory[] $partyCategories1
 * @property PartyAddress[] $partyAddresses
 * @property PartyAddress[] $partyAddresses1
 * @property GnuhealthFamilyMember[] $gnuhealthFamilyMembers
 * @property GnuhealthFamilyMember[] $gnuhealthFamilyMembers1
 * @property ResUser $createU
 * @property ResUser[] $resUsers
 * @property ResUser $writeU
 * @property ResUser[] $resUsers1
 * @property PartyParty[] $partyParties
 * @property PartyParty[] $partyParties1
 * @property PartyParty[] $partyParties2
 * @property PartyCategoryRel[] $partyCategoryRels
 * @property PartyCategoryRel[] $partyCategoryRels1
 * @property GnuhealthPhysician[] $gnuhealthPhysicians
 * @property GnuhealthPhysician[] $gnuhealthPhysicians1
 * @property GnuhealthPatient[] $gnuhealthPatients
 * @property GnuhealthPatient[] $gnuhealthPatients1
 * @property GnuhealthOccupation[] $gnuhealthOccupations
 * @property GnuhealthOccupation[] $gnuhealthOccupations1
 * @property GnuhealthHospitalWard[] $gnuhealthHospitalWards
 * @property GnuhealthHospitalWard[] $gnuhealthHospitalWards1
 * @property GnuhealthEthnicity[] $gnuhealthEthnicities
 * @property GnuhealthEthnicity[] $gnuhealthEthnicities1
 * @property GnuhealthFamily[] $gnuhealthFamilies
 * @property GnuhealthFamily[] $gnuhealthFamilies1
 */
class ResUser extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'res_user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, login, menu, login_try', 'required'),
			array('create_uid, write_uid, menu, language, login_try, main_company, employee, company', 'numerical', 'integerOnly'=>true),
			array('create_date, write_date', 'length', 'max'=>6),
			array('salt', 'length', 'max'=>8),
			array('active, password, timezone, email, signature', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, name, active, login, password, create_date, write_date, create_uid, write_uid, timezone, menu, email, language, login_try, signature, salt, main_company, employee, company', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'partyCategories' => array(self::HAS_MANY, 'PartyCategory', 'create_uid'),
			'partyCategories1' => array(self::HAS_MANY, 'PartyCategory', 'write_uid'),
			'partyAddresses' => array(self::HAS_MANY, 'PartyAddress', 'create_uid'),
			'partyAddresses1' => array(self::HAS_MANY, 'PartyAddress', 'write_uid'),
			'gnuhealthFamilyMembers' => array(self::HAS_MANY, 'GnuhealthFamilyMember', 'create_uid'),
			'gnuhealthFamilyMembers1' => array(self::HAS_MANY, 'GnuhealthFamilyMember', 'write_uid'),
			'createU' => array(self::BELONGS_TO, 'ResUser', 'create_uid'),
			'resUsers' => array(self::HAS_MANY, 'ResUser', 'create_uid'),
			'writeU' => array(self::BELONGS_TO, 'ResUser', 'write_uid'),
			'resUsers1' => array(self::HAS_MANY, 'ResUser', 'write_uid'),
			'partyParties' => array(self::HAS_MANY, 'PartyParty', 'create_uid'),
			'partyParties1' => array(self::HAS_MANY, 'PartyParty', 'internal_user'),
			'partyParties2' => array(self::HAS_MANY, 'PartyParty', 'write_uid'),
			'partyCategoryRels' => array(self::HAS_MANY, 'PartyCategoryRel', 'create_uid'),
			'partyCategoryRels1' => array(self::HAS_MANY, 'PartyCategoryRel', 'write_uid'),
			'gnuhealthPhysicians' => array(self::HAS_MANY, 'GnuhealthPhysician', 'create_uid'),
			'gnuhealthPhysicians1' => array(self::HAS_MANY, 'GnuhealthPhysician', 'write_uid'),
			'gnuhealthPatients' => array(self::HAS_MANY, 'GnuhealthPatient', 'create_uid'),
			'gnuhealthPatients1' => array(self::HAS_MANY, 'GnuhealthPatient', 'write_uid'),
			'gnuhealthOccupations' => array(self::HAS_MANY, 'GnuhealthOccupation', 'create_uid'),
			'gnuhealthOccupations1' => array(self::HAS_MANY, 'GnuhealthOccupation', 'write_uid'),
			'gnuhealthHospitalWards' => array(self::HAS_MANY, 'GnuhealthHospitalWard', 'create_uid'),
			'gnuhealthHospitalWards1' => array(self::HAS_MANY, 'GnuhealthHospitalWard', 'write_uid'),
			'gnuhealthEthnicities' => array(self::HAS_MANY, 'GnuhealthEthnicity', 'create_uid'),
			'gnuhealthEthnicities1' => array(self::HAS_MANY, 'GnuhealthEthnicity', 'write_uid'),
			'gnuhealthFamilies' => array(self::HAS_MANY, 'GnuhealthFamily', 'create_uid'),
			'gnuhealthFamilies1' => array(self::HAS_MANY, 'GnuhealthFamily', 'write_uid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'active' => 'Active',
			'login' => 'Login',
			'password' => 'Password',
			'create_date' => 'Create Date',
			'write_date' => 'Write Date',
			'create_uid' => 'Create Uid',
			'write_uid' => 'Write Uid',
			'timezone' => 'Timezone',
			'menu' => 'Menu',
			'email' => 'Email',
			'language' => 'Language',
			'login_try' => 'Login Try',
			'signature' => 'Signature',
			'salt' => 'Salt',
			'main_company' => 'Main Company',
			'employee' => 'Employee',
			'company' => 'Company',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('active',$this->active);
		$criteria->compare('login',$this->login,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('create_date',$this->create_date,true);
		$criteria->compare('write_date',$this->write_date,true);
		$criteria->compare('create_uid',$this->create_uid);
		$criteria->compare('write_uid',$this->write_uid);
		$criteria->compare('timezone',$this->timezone,true);
		$criteria->compare('menu',$this->menu);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('language',$this->language);
		$criteria->compare('login_try',$this->login_try);
		$criteria->compare('signature',$this->signature,true);
		$criteria->compare('salt',$this->salt,true);
		$criteria->compare('main_company',$this->main_company);
		$criteria->compare('employee',$this->employee);
		$criteria->compare('company',$this->company);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return ResUser the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
